-- monster_miss.lua
-- Created by zouyb Jun/04/2015
-- 怪物闪避后触发下一个引导

return {
    -- 添加格子开启时的回调
    register = function(config)
        local function handle(para)
            local id = para["id"];
			local _, _, monsterId, maxMissTimes = string.find(config.para, "(%d+),[ ]*(%d+)"); 
            if id ~= tonumber(monsterId) then
                return;
            end
            
            maxMissTimes = tonumber(maxMissTimes);
            
			-- 当前闪避次数
            local curMissTimes = ME.user.dbase:queryTemp("monster_miss_"..id, 1);

            print("monster_miss: id:" .. id .. ", times:" .. curMissTimes);

			-- 闪避次数满足触发要求
			if curMissTimes >= maxMissTimes then
                -- 继续下一个引导
                UIDungeonMgr.getCurLevel().guideMgr:runNext();
			else
                -- 增加闪避次数
                ME.user.dbase:setTemp("monster_miss_"..id, curMissTimes + 1);
			end
        end

        EventMgr.remove("guide_monster_miss", event.MONSTER_DODGE);
        EventMgr.register("guide_monster_miss", event.MONSTER_DODGE, handle);
    end,

    -- 删除格子开启时的回调
    unRegister = function(config)
        EventMgr.remove("guide_monster_miss", event.MONSTER_DODGE);

		-- 重置闪避次数
		local _, _, monsterId, maxMissTimes = string.find(config.para, "(%d+),[ ]*(%d+)"); 
		ME.user.dbase:setTemp("monster_miss"..monsterId, 0);
    end
};